package com.ie.cloud.payment.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class RequestInterceptor implements HandlerInterceptor {

    @Resource
    private VerifyUtils verifyUtils;



    @Override
    @SuppressWarnings("all")
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {



        log.info("请求拦截器 - 请求开始 - URI: {}, Method: {}", request.getRequestURI(), request.getMethod());

        return verifyUtils.verifyV1(request, response, handler);

    }


    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("请求拦截器 - 请求结束 - URI: {}, Status: {}", request.getRequestURI(), response.getStatus());
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        if (ex != null) {
            log.error("请求拦截器 - 请求异常 - URI: {}, Error: {}", request.getRequestURI(), ex.getMessage());
        }
    }

}
